package top.hcode.hoj.utils;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.extern.slf4j.Slf4j;
import org.nutz.lang.Files;
import org.nutz.lang.Lang;
import org.nutz.lang.util.NutMap;

import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author orangej
 * @since 2025/1/22
 */
@Slf4j
public class CommonMethods {


    /**
     * 解析班级编号
     */
    public static Integer parseClassNum(String name) {
        // 从 一年级8班, 一年级17班 名称获取班级编号
        Pattern pattern = Pattern.compile("(\\d+)班");
        Matcher matcher = pattern.matcher(name);
        if (matcher.find()) {
            return Integer.parseInt(matcher.group(1));
        }

        return null;
    }

    public static NutMap obj2HumpMap(Object obj) {
        return obj2HumpMap(obj, null);
    }

    public static NutMap obj2HumpMap(Object obj, String... excludeFields) {
        NutMap map = Lang.obj2nutmap(obj);
        Set<String> keySet = new HashSet<>(map.keySet());
        for (String key : keySet) {
            if (Lang.isNotEmpty(excludeFields) && ArrayUtil.contains(excludeFields, key)) {
                continue;
            }

            String humpKey = StrUtil.toUnderlineCase(key);
            if (key.equals(humpKey)) {
                continue;
            }
            map.put(humpKey, map.get(key));
            map.remove(key);
        }
        return map;
    }



    public static void main(String[] args) {
        System.out.println(parseClassNum("一年级8班"));
        System.out.println(parseClassNum("一年级18班"));

        for (int i = 0; i < 10; i++) {
            System.out.println(IdWorker.getIdStr());
        }
    }

}
